package com.wanmait.bootdemo.filter;

import com.wanmait.bootdemo.pojo.QuestionType;
import com.wanmait.bootdemo.service.QuestionTypeService;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.*;
import java.io.IOException;
import java.util.List;

//@WebFilter("/*")
public class LoginFilter implements Filter {


    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        //servlet 过滤器 监听器 从spring容器中获取对象使用下面的方式
        ApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(servletRequest.getServletContext());
        QuestionTypeService questionTypeService = applicationContext.getBean("questionTypeServiceImpl",QuestionTypeService.class);
        List<QuestionType> questionTypes = questionTypeService.findAll();

        questionTypes.forEach(System.out::println);

        System.out.println("111111111111111111111111111");
        System.out.println("login filter.........................");
        filterChain.doFilter(servletRequest, servletResponse);
        System.out.println("22222222222222222222222");
    }
}
